package com.ruoyi.common.core.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class TimeZoneTransition {

    public static String transition(String dateTime) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        formatter.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai")); // 设置源时区
        Date sourceDate = null;
        try {
            sourceDate = formatter.parse(dateTime);
            formatter.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); // 设置目标时区
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String targetDate = formatter.format(sourceDate);
        System.out.println(targetDate); // 输出：2023-03-14 21:00:00
        return targetDate;
    }

    public static String transitionTwo(String dateTime) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        formatter.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); // 设置目标时区
        Date sourceDate = null;
        try {
            sourceDate = formatter.parse(dateTime);
            formatter.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai")); // 设置源时区
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String targetDate = formatter.format(sourceDate);
        System.out.println(targetDate); // 输出：2023-03-14 21:00:00
        return targetDate;
    }

}
